package org.teachertools.web;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.Validate;
import org.apache.log4j.Logger;

public class DateConvertUtils {

    private static final Logger logger = Logger.getLogger(DateConvertUtils.class);

    public static Date parseDate(String value, String format) {
        Validate.notEmpty(value, "Date value is missing");
        Validate.notEmpty(format, "Date format is missing");
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return sdf.parse(value);
        } catch (Exception e) {
            logger.warn("Cant parse date: "+value+" with format: "+format, e);
            return null;
        }
    }
}
